package com.system.manager.modules.authorized.controller;


import com.system.manager.common.annotation.Anonymous;
import com.system.manager.common.annotation.PreAuthorize;
import com.system.manager.common.entity.Result;
import com.system.manager.modules.authorized.entity.SystemMenu;
import com.system.manager.modules.authorized.enums.SubjectType;
import com.system.manager.modules.authorized.service.ISystemMenuService;
import com.system.manager.modules.authorized.service.SysMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 系统菜单表 前端控制器
 * </p>
 *
 * @author yxp
 * @since 2021-10-18
 */
@Api(tags = "角色权限管理API")
@RestController
@RequestMapping("/authorized/")
@Slf4j
public class SystemMenuController {

    @Autowired
    private SysMenuService sysService;

    @Autowired
    private ISystemMenuService systemService;


//    @PreAuthorize(SubjectType.ANONYMOUS)
    @Anonymous
    @ApiOperation("用户登陆时，获取已有的权限")
    @GetMapping("menu/{role}")
    public Map<String, Object> menu(@PathVariable("role") Integer role) {
        log.info("--->访问了菜单");
        // 根据角色获取当前的权限菜单
        Map<String, Object> menu = sysService.menu(role);

        return menu;
    }

    @ApiOperation("获取所有菜单授权的url")
    @PreAuthorize(SubjectType.ANONYMOUS)
    @GetMapping("menu/list")
    public Result menuList(){


        List<SystemMenu> systemMenus = systemService.selectMenuList();

        return Result.ok(systemMenus);
    }
}
